package business;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.ListIterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Hashtable;

import dao.CollectivityHomeworkDAO;
import dao.CollectivityHomeworkInfoDAO;
import dao.CollectivityTeachingPlanDAO;
import dao.IHomeworkDomainDAO;
import dao.IHomeworkDomainInfoDAO;
import dao.IndividualHomeworkDAO;
import dao.IndividualTeachingPlanDAO;
import dao.StudentDAO;
import dao.TeacherDAO;
import dao.TeachingPlanBaseInfoDAO;
import dao.AORefDAO;
import dao.ChildrenBehaviorPurposeDAO;
import dao.UserCollectionDAO;

import orm.AORef;
import orm.ChildrenBehaviorPurpose;
import orm.CollectivityHomework;
import orm.CollectivityHomeworkInfo;
import orm.CollectivityTeachingPlan;
import orm.IHomeworkDomain;
import orm.IHomeworkDomainInfo;
import orm.IndividualHomework;
import orm.IndividualTeachingPlan;
import orm.Teacher;
import orm.TeachingPlanBaseInfo;
import util.DBHelper;
import util.Utility;
import util.WebConstants;

public class MyTeachingPlan extends BaseServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public MyTeachingPlan() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String strFunc = request.getParameter("func");
		Connection con = null;
		Statement stmt = null;
		if (strFunc.equals("load")) {
			myTeachingPlan(request, response);
			
			
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("share")) {
			String strTPID = request.getParameter("hdTPID");
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			try {
				if(tpbiDAO.selectShareByTPID(strTPID)){
					request.setAttribute("flagShare", "flagShare");
					myTeachingPlan(request, response);
					request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
					return;
				}
				tpbiDAO.shareTPByTPID(strTPID);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			myTeachingPlan(request, response);
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("edit")) {
			String strTPID = request.getParameter("hdTPID");
			StudentDAO studentDAO = new StudentDAO();
			Hashtable<Integer, String> ht = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			String teacherName = teacher.getTname();

			try {
				TeachingPlanBaseInfo tpbi = tpbiDAO.getTPByTPID(strTPID);
				if (tpbi.getTpType() == Utility.TEACHINGPLAN_TYPE_INDIVIDUAL) {				
					IndividualTeachingPlanDAO itpDAO = new IndividualTeachingPlanDAO();
					IndividualTeachingPlan itp = itpDAO.getITPByTPID(strTPID);
					
					TeacherDAO teacherDAO = new TeacherDAO();
					
					
					AORefDAO aoRefDAO = new AORefDAO();
					ArrayList<AORef> al = new ArrayList<AORef>();
					al = aoRefDAO.getAORefArrByTPID(strTPID);
					
					IndividualHomeworkDAO ihwDAO = new IndividualHomeworkDAO();
					IndividualHomework ihw = ihwDAO.getIHWByTPID(strTPID);
					
					IHomeworkDomainDAO ihwdDAO = new IHomeworkDomainDAO();
					ArrayList<IHomeworkDomain> alIHWD = new ArrayList<IHomeworkDomain>();
					alIHWD = ihwdDAO.getIHWDByTPID(strTPID);
					
					IHomeworkDomainInfoDAO ihwdiDAO = new IHomeworkDomainInfoDAO();
					ArrayList<IHomeworkDomainInfo> alIHWDI = new ArrayList<IHomeworkDomainInfo>();
					alIHWDI = ihwdiDAO.getIHWDIByTPID(strTPID);
					
					ht = studentDAO.getStudentsByIndiTeacherID(teacherID);
					
					request.setAttribute("Students", ht);
					request.setAttribute("TPBI", tpbi);
					request.setAttribute("ITP", itp);
					request.setAttribute("AORefArr", al);
					request.setAttribute("IHW", ihw);
					request.setAttribute("IHWDArr", alIHWD);
					request.setAttribute("IHWDIArr", alIHWDI);
					request.setAttribute("teacherName", teacherName);
					
					
					request.getRequestDispatcher("../" + 
							Utility.JSP_ITPEdit).forward(request, response);
				} else {
					CollectivityTeachingPlanDAO ctpDAO = new CollectivityTeachingPlanDAO();
					CollectivityTeachingPlan ctp = ctpDAO.getCTPByTPID(strTPID);
					
					ChildrenBehaviorPurposeDAO cbpDAO = new ChildrenBehaviorPurposeDAO();
					CollectivityHomeworkDAO chwDAO = new CollectivityHomeworkDAO();
					CollectivityHomework chw = chwDAO.getCHWByTPID(strTPID);
					CollectivityHomeworkInfoDAO chwiDAO = new CollectivityHomeworkInfoDAO();
					
					TeacherDAO teacherDAO = new TeacherDAO();
					
					ArrayList<ChildrenBehaviorPurpose> al = cbpDAO.getChildrenBehaviorPurposeArrayByTPID(strTPID);
					ArrayList<CollectivityHomeworkInfo> alCHWI = chwiDAO.getCHWIByTPID(strTPID);
					
					ht = studentDAO.getStudentsByTeacherID(teacherID);
					
					request.setAttribute("Students", ht);
					request.setAttribute("TPBI", tpbi);
					request.setAttribute("CTP", ctp);
					request.setAttribute("CBPArr", al);
					request.setAttribute("CHW", chw);
					request.setAttribute("CHWIArr", alCHWI);
					request.setAttribute("teacherName", teacherName);
					

					request.getRequestDispatcher("../" + 
							Utility.JSP_CTPEdit).forward(request, response);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}

		} else if (strFunc.equals("delete")) {
			String strTPID = request.getParameter("hdTPID");
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			String teacherName = teacher.getTname();	
			try {
				con = DBHelper.getConnection();
				con.setAutoCommit(false);
				stmt = con.createStatement();
				
				TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
				TeachingPlanBaseInfo tpbi = tpbiDAO.getTPByTPID(strTPID);
				
				if (tpbi.getTpType() == Utility.TEACHINGPLAN_TYPE_INDIVIDUAL) {
					IndividualTeachingPlanDAO itpDAO = new IndividualTeachingPlanDAO();
					itpDAO.deleteITP(stmt, strTPID);
					
					AORefDAO aoRefDAO = new AORefDAO();
					aoRefDAO.deleteAORef(stmt, strTPID);
					
					
					IndividualHomeworkDAO ihwDAO = new IndividualHomeworkDAO();
					ihwDAO.deleteIHW(stmt, strTPID);
					
					IHomeworkDomainDAO ihwdDAO = new IHomeworkDomainDAO();
					ihwdDAO.deleteIHomeworkDomain(stmt, strTPID);
					
					IHomeworkDomainInfoDAO ihwdiDAO = new IHomeworkDomainInfoDAO();
					ihwdiDAO.deleteIHomeworkDomainInfo(stmt, strTPID);
					
					
				} else {
					CollectivityTeachingPlanDAO ctpDAO = new CollectivityTeachingPlanDAO();
					ctpDAO.deleteCTP(stmt, strTPID);
					
					ChildrenBehaviorPurposeDAO cbpDAO = new ChildrenBehaviorPurposeDAO();
					cbpDAO.deleteChildrenBehaviorPurpose(stmt, strTPID);
					
					CollectivityHomeworkDAO chwDAO = new CollectivityHomeworkDAO();
					chwDAO.deletechw(stmt, strTPID);
					
					CollectivityHomeworkInfoDAO chwiDAO = new CollectivityHomeworkInfoDAO();
					chwiDAO.deleteCHomeworkInfo(stmt, strTPID);
				}
				
				tpbiDAO.deleteTPByTPID(stmt, strTPID);
				
				con.commit();
				stmt.close();
				
				int PageSize = Utility.PageSize;
				String tmp = request.getParameter("HDPageNo");
				int nPageNo = Integer.parseInt(tmp); 
				ArrayList alTP = tpbiDAO.getTPByUserName(teacherID);
				int totalPage = 0;
				if (alTP.size() % PageSize == 0) {
					totalPage = alTP.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (alTP.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				
				request.setAttribute("pageNo", 1);
				
				ArrayList<TeachingPlanBaseInfo> al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getTPByUserName(teacherID).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					TeachingPlanBaseInfo t = it.next();
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setEditingTimes(t.getEditingTimes());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);
					
					ii++;
					if(ii > (PageSize-1) ) {
						break;
					}
					
				}
				
				
				request.setAttribute("TPList", al);
				
				ArrayList coll = new ArrayList();
				coll = tpbiDAO.getCollectTPByUserName(teacherID);
				if(coll != null){
				request.setAttribute("collectionTPList", tpbiDAO.getCollectTPByUserName(teacherID));
				}
				
				request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
				try {
					con.rollback();
				} catch (SQLException ee) {
					ee.printStackTrace();
				}
			}

		} else if (strFunc.equals("paging")) {
			int PageSize = Utility.PageSize;
			String strSub = request.getParameter("sub");
			String tmp = request.getParameter("HDPageNo");
			int nPageNo = Integer.parseInt(tmp); 
			TeachingPlanBaseInfo tpbi = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int tpType = 0;
			int tpProperty = 0;
			int appropriateAge = 0;
			String monthThemeName = null;
			String weekThemeName = null;
			int developmentDomain = 0;
			int aggrandizementDomain = 0;
			int activityType = 0;
			String tpYear = null;
			
			if(request.getParameter("TPType") != null && !request.getParameter("TPType").equals("")){
				tpType = Integer.parseInt(request.getParameter("TPType"));
			}
			if(request.getParameter("TPProperty") != null && !request.getParameter("TPProperty").equals("")){
				tpProperty = Integer.parseInt(request.getParameter("TPProperty"));
			}
			if(request.getParameter("AppropriateAge") != null && !request.getParameter("AppropriateAge").equals("")){
				appropriateAge = Integer.parseInt(request.getParameter("AppropriateAge"));
			}
			if(request.getParameter("MonthThemeName") != null && !request.getParameter("MonthThemeName").equals("")){
				monthThemeName = request.getParameter("MonthThemeName");
			}
			if(request.getParameter("WeekThemeName") != null && !request.getParameter("WeekThemeName").equals("")){
				weekThemeName = request.getParameter("WeekThemeName");
				
			}
			if(request.getParameter("DevelopmentDomain") != null && !request.getParameter("DevelopmentDomain").equals("")){
				developmentDomain = Integer.parseInt(request.getParameter("DevelopmentDomain"));
			}
			if(request.getParameter("AggrandizementDomain") != null && !request.getParameter("AggrandizementDomain").equals("")){
				aggrandizementDomain = Integer.parseInt(request.getParameter("AggrandizementDomain"));
			}
			if(request.getParameter("ActivityType") != null && !request.getParameter("ActivityType").equals("")){
				activityType = Integer.parseInt(request.getParameter("ActivityType"));
			}
			if(request.getParameter("TPYear") != null && !request.getParameter("TPYear").equals("")){
				tpYear = request.getParameter("TPYear");
				
			}
			
			try {
//				request.setAttribute("pageNo", nPageNo);
				ArrayList al = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear);
				
				
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (al.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				if (strSub == null)
				{
					
				} else if (strSub.equals("start")) {
					nPageNo = 1;
				} else if (strSub.equals("front")) {
					nPageNo--;
				} else if (strSub.equals("next")) {
					nPageNo++;
				} else if (strSub.equals("last")) {
					nPageNo = totalPage ;
				} 
				request.setAttribute("pageNo", nPageNo);
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					ii++;
					TeachingPlanBaseInfo t = it.next();
					if (ii <= PageSize * (nPageNo - 1))
						continue;
					
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setEditingTimes(t.getEditingTimes());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);

					if(ii > PageSize * nPageNo - 1 ) {
						break;
					}
				}
				
				request.setAttribute("TPList", al);

				
				
				request.setAttribute("pageNoColl", 1);
				int PageSizeColl = Utility.PageSize;
				ArrayList alColl = tpbiDAO.getCollectTPByUserName(teacherID);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				TeachingPlanBaseInfo tpbiColl = null;
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getCollectTPByUserName(teacherID).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					TeachingPlanBaseInfo t = itColl.next();
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
					tpbiColl.setEditingTimes(t.getEditingTimes());
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					iiColl++;
		
					if(iiColl > (PageSizeColl-1) ) {
						break;
					}
				}
				
				request.setAttribute("collectionTPList", alColl);
				
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
//			myTeachingPlan(request, response);
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("searchPage")) {
			int PageSize = Utility.PageSize;
			String strSub = request.getParameter("sub");
			String tmp = request.getParameter("PageNo");
			int nPageNo = Integer.parseInt(tmp);
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int tpType = 0;
			int tpProperty = 0;
			int appropriateAge = 0;
			String monthThemeName = null;
			String weekThemeName = null;
			int developmentDomain = 0;
			int aggrandizementDomain = 0;
			int activityType = 0;
			String tpYear = null;
			
			if(request.getParameter("TPType") != null && !request.getParameter("TPType").equals("")){
				tpType = Integer.parseInt(request.getParameter("TPType"));
			}
			if(request.getParameter("TPProperty") != null && !request.getParameter("TPProperty").equals("")){
				tpProperty = Integer.parseInt(request.getParameter("TPProperty"));
			}
			if(request.getParameter("AppropriateAge") != null && !request.getParameter("AppropriateAge").equals("")){
				appropriateAge = Integer.parseInt(request.getParameter("AppropriateAge"));
			}
			if(request.getParameter("MonthThemeName") != null && !request.getParameter("MonthThemeName").equals("")){
				monthThemeName = request.getParameter("MonthThemeName");
			}
			if(request.getParameter("WeekThemeName") != null && !request.getParameter("WeekThemeName").equals("")){
				weekThemeName = request.getParameter("WeekThemeName");
				
			}
			if(request.getParameter("DevelopmentDomain") != null && !request.getParameter("DevelopmentDomain").equals("")){
				developmentDomain = Integer.parseInt(request.getParameter("DevelopmentDomain"));
			}
			if(request.getParameter("AggrandizementDomain") != null && !request.getParameter("AggrandizementDomain").equals("")){
				aggrandizementDomain = Integer.parseInt(request.getParameter("AggrandizementDomain"));
			}
			if(request.getParameter("ActivityType") != null && !request.getParameter("ActivityType").equals("")){
				activityType = Integer.parseInt(request.getParameter("ActivityType"));
			}
			if(request.getParameter("TPYear") != null && !request.getParameter("TPYear").equals("")){
				tpYear = request.getParameter("TPYear");
				
			}
			
			TeachingPlanBaseInfo tpbi = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			try {
//				request.setAttribute("pageNo", nPageNo);
				ArrayList al = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear);
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = al.size()/PageSize + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				request.setAttribute("pageNo", nPageNo);
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					ii++;
					TeachingPlanBaseInfo t = it.next();
					if (ii <= PageSize * (nPageNo - 1))
						continue;
					
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setEditingTimes(t.getEditingTimes());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);

					if(ii > PageSize * nPageNo - 1 ) {
						break;
					}
				}
				
				request.setAttribute("TPList", al);
				
				
				request.setAttribute("pageNoColl", 1);
				int PageSizeColl = Utility.PageSize;
				ArrayList alColl = tpbiDAO.getCollectTPByUserName(teacherID);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				TeachingPlanBaseInfo tpbiColl = null;
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getCollectTPByUserName(teacherID).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					TeachingPlanBaseInfo t = itColl.next();
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
					tpbiColl.setEditingTimes(t.getEditingTimes());
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					iiColl++;
		
					if(iiColl > (PageSizeColl-1) ) {
						break;
					}
				}
				
				request.setAttribute("collectionTPList", alColl);
				
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("collectionTP")) {
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			try {
				
				request.setAttribute("collectionTPList", tpbiDAO.getCollectTPByUserName(teacherID));
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
			try {
				collectionTeachingPlan(request, response);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			request.setAttribute(WebConstants.DIVSHOW, WebConstants.DIV_COLL);
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
			
		} else if (strFunc.equals("myTP")) {
			
		} else if (strFunc.equals("editCollection")){
			
			
			String strTPID = request.getParameter("colTPID");
			StudentDAO studentDAO = new StudentDAO();
			Hashtable<Integer, String> ht = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			request.setAttribute("favor", "favor");
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			String teacherName = teacher.getTname();
			try {
				TeachingPlanBaseInfo tpbi = tpbiDAO.getTPByTPID(strTPID);
				if (tpbi.getTpType() == Utility.TEACHINGPLAN_TYPE_INDIVIDUAL) {				
					IndividualTeachingPlanDAO itpDAO = new IndividualTeachingPlanDAO();
					IndividualTeachingPlan itp = itpDAO.getITPByTPID(strTPID);
					
					TeacherDAO teacherDAO = new TeacherDAO();
					
					
					AORefDAO aoRefDAO = new AORefDAO();
					ArrayList<AORef> al = new ArrayList<AORef>();
					al = aoRefDAO.getAORefArrByTPID(strTPID);
					
					IndividualHomeworkDAO ihwDAO = new IndividualHomeworkDAO();
					IndividualHomework ihw = ihwDAO.getIHWByTPID(strTPID);
					
					IHomeworkDomainDAO ihwdDAO = new IHomeworkDomainDAO();
					ArrayList<IHomeworkDomain> alIHWD = new ArrayList<IHomeworkDomain>();
					alIHWD = ihwdDAO.getIHWDByTPID(strTPID);
					
					IHomeworkDomainInfoDAO ihwdiDAO = new IHomeworkDomainInfoDAO();
					ArrayList<IHomeworkDomainInfo> alIHWDI = new ArrayList<IHomeworkDomainInfo>();
					alIHWDI = ihwdiDAO.getIHWDIByTPID(strTPID);
					
					ht = studentDAO.getStudentsByIndiTeacherID(teacherID);
					
					request.setAttribute("Students", ht);
					request.setAttribute("TPBI", tpbi);
					request.setAttribute("ITP", itp);
					request.setAttribute("AORefArr", al);
					request.setAttribute("IHW", ihw);
					request.setAttribute("IHWDArr", alIHWD);
					request.setAttribute("IHWDIArr", alIHWDI);
					request.setAttribute("teacherName", teacherName);
					
					
					request.getRequestDispatcher("../" + 
							Utility.JSP_ITPEdit).forward(request, response);
				} else {
					CollectivityTeachingPlanDAO ctpDAO = new CollectivityTeachingPlanDAO();
					CollectivityTeachingPlan ctp = ctpDAO.getCTPByTPID(strTPID);
					
					ChildrenBehaviorPurposeDAO cbpDAO = new ChildrenBehaviorPurposeDAO();
					CollectivityHomeworkDAO chwDAO = new CollectivityHomeworkDAO();
					CollectivityHomework chw = chwDAO.getCHWByTPID(strTPID);
					CollectivityHomeworkInfoDAO chwiDAO = new CollectivityHomeworkInfoDAO();
					
					TeacherDAO teacherDAO = new TeacherDAO();
					
					ArrayList<ChildrenBehaviorPurpose> al = cbpDAO.getChildrenBehaviorPurposeArrayByTPID(strTPID);
					ArrayList<CollectivityHomeworkInfo> alCHWI = chwiDAO.getCHWIByTPID(strTPID);
					
					ht = studentDAO.getStudentsByTeacherID(teacherID);
					
					request.setAttribute("Students", ht);
					request.setAttribute("TPBI", tpbi);
					request.setAttribute("CTP", ctp);
					request.setAttribute("CBPArr", al);
					request.setAttribute("CHW", chw);
					request.setAttribute("CHWIArr", alCHWI);
					request.setAttribute("teacherName", teacherName);
					

					request.getRequestDispatcher("../" + 
							Utility.JSP_CTPEdit).forward(request, response);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		} else if (strFunc.equals("deleteCollection")){
			String strTPID = request.getParameter("colTPID");
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			try {
				con = DBHelper.getConnection();
				con.setAutoCommit(false);
				stmt = con.createStatement();
				
				UserCollectionDAO ucDAO = new UserCollectionDAO();
				TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
				TeachingPlanBaseInfo tpbi = tpbiDAO.getTPByTPID(strTPID);
				
				ucDAO.undoCollectByTPID(teacherID, strTPID);
				
				con.commit();
				stmt.close();
				
				
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
				try {
					con.rollback();
				} catch (SQLException ee) {
					ee.printStackTrace();
				}
			}
			myTeachingPlan(request, response);
			
			request.setAttribute(WebConstants.DIVSHOW, WebConstants.DIV_COLL);

			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
//			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("pagingCollection")){
			int PageSizeColl = Utility.PageSize;
			TeachingPlanBaseInfo tpbiColl = null;
			String strSub = request.getParameter("sub");
			String tmp = request.getParameter("pageNoColl");
			int nPageNo = Integer.parseInt(tmp); 
			TeachingPlanBaseInfo tpbi = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int coltpType = 0;
			int coltpProperty = 0;
			int colappropriateAge = 0;
			String colmonthThemeName = null;
			String colweekThemeName = null;
			int coldevelopmentDomain = 0;
			int colaggrandizementDomain = 0;
			int colactivityType = 0;
			String coltpYear = null;
			
			if(request.getParameter("ColTPType") != null && !request.getParameter("ColTPType").equals("")){
				coltpType = Integer.parseInt(request.getParameter("ColTPType"));
			}
			if(request.getParameter("ColTPProperty") != null && !request.getParameter("ColTPProperty").equals("")){
				coltpProperty = Integer.parseInt(request.getParameter("ColTPProperty"));
			}
			if(request.getParameter("ColAppropriateAge") != null && !request.getParameter("ColAppropriateAge").equals("")){
				colappropriateAge = Integer.parseInt(request.getParameter("ColAppropriateAge"));
			}
			if(request.getParameter("ColMonthThemeName") != null && !request.getParameter("ColMonthThemeName").equals("")){
				colmonthThemeName = request.getParameter("ColMonthThemeName");
			}
			if(request.getParameter("ColWeekThemeName") != null && !request.getParameter("ColWeekThemeName").equals("")){
				colweekThemeName = request.getParameter("ColWeekThemeName");
				
			}
			if(request.getParameter("ColDevelopmentDomain") != null && !request.getParameter("ColDevelopmentDomain").equals("")){
				coldevelopmentDomain = Integer.parseInt(request.getParameter("ColDevelopmentDomain"));
			}
			if(request.getParameter("ColAggrandizementDomain") != null && !request.getParameter("ColAggrandizementDomain").equals("")){
				colaggrandizementDomain = Integer.parseInt(request.getParameter("ColAggrandizementDomain"));
			}
			if(request.getParameter("ColActivityType") != null && !request.getParameter("ColActivityType").equals("")){
				colactivityType = Integer.parseInt(request.getParameter("ColActivityType"));
			}
			if(request.getParameter("ColTPYear") != null && !request.getParameter("ColTPYear").equals("")){
				coltpYear = request.getParameter("ColTPYear");
				
			}
			
			
			try {
				
				
//				request.setAttribute("pageNo", nPageNo);
				ArrayList alColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				if (strSub == null)
				{
					
				} else if (strSub.equals("start")) {
					nPageNo = 1;
				} else if (strSub.equals("front")) {
					nPageNo--;
				} else if (strSub.equals("next")) {
					nPageNo++;
				} else if (strSub.equals("last")) {
					nPageNo = totalPageColl ;
				} 
				request.setAttribute("pageNoColl", nPageNo);
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					iiColl++;
					TeachingPlanBaseInfo t = itColl.next();
					if(iiColl <= PageSizeColl * (nPageNo - 1))
						continue;
					
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
					tpbiColl.setEditingTimes(t.getEditingTimes());
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					
					if(iiColl > PageSizeColl * nPageNo - 1){
						break;
					}
					
				}
				request.setAttribute("collectionTPList", alColl);
				
				request.setAttribute("pageNo", 1);
				int PageSize = Utility.PageSize;
				
				int tpType = 0;
				int tpProperty = 0;
				int appropriateAge = 0;
				String monthThemeName = null;
				String weekThemeName = null;
				int developmentDomain = 0;
				int aggrandizementDomain = 0;
				int activityType = 0;
				String tpYear = null;
				
				if(request.getParameter("TPType") != null && !request.getParameter("TPType").equals("")){
					tpType = Integer.parseInt(request.getParameter("TPType"));
				}
				if(request.getParameter("TPProperty") != null && !request.getParameter("TPProperty").equals("")){
					tpProperty = Integer.parseInt(request.getParameter("TPProperty"));
				}
				if(request.getParameter("AppropriateAge") != null && !request.getParameter("AppropriateAge").equals("")){
					appropriateAge = Integer.parseInt(request.getParameter("AppropriateAge"));
				}
				if(request.getParameter("MonthThemeName") != null && !request.getParameter("MonthThemeName").equals("")){
					monthThemeName = request.getParameter("MonthThemeName");
				}
				if(request.getParameter("WeekThemeName") != null && !request.getParameter("WeekThemeName").equals("")){
					weekThemeName = request.getParameter("WeekThemeName");
					
				}
				if(request.getParameter("DevelopmentDomain") != null && !request.getParameter("DevelopmentDomain").equals("")){
					developmentDomain = Integer.parseInt(request.getParameter("DevelopmentDomain"));
				}
				if(request.getParameter("AggrandizementDomain") != null && !request.getParameter("AggrandizementDomain").equals("")){
					aggrandizementDomain = Integer.parseInt(request.getParameter("AggrandizementDomain"));
				}
				if(request.getParameter("ActivityType") != null && !request.getParameter("ActivityType").equals("")){
					activityType = Integer.parseInt(request.getParameter("ActivityType"));
				}
				if(request.getParameter("TPYear") != null && !request.getParameter("TPYear").equals("")){
					tpYear = request.getParameter("TPYear");
					
				}
				
				
				
				ArrayList al = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear);
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (al.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					TeachingPlanBaseInfo t = it.next();
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
					tpbi.setEditingTimes(t.getEditingTimes());
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);
					ii++;
		
					if(ii > (PageSize-1) ) {
						break;
					}
				}
				
			
				request.setAttribute("TPList", al);
				
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute(WebConstants.DIVSHOW, WebConstants.DIV_COLL);
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
			
		} else if (strFunc.equals("searchPageCollection")){
			int PageSizeColl = Utility.PageSize;
			TeachingPlanBaseInfo tpbiColl = null;
			String strSub = request.getParameter("sub");
			String tmp = request.getParameter("pageNoCollSel");
			int nPageNo = Integer.parseInt(tmp); 
			TeachingPlanBaseInfo tpbi = null;
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int coltpType = 0;
			int coltpProperty = 0;
			int colappropriateAge = 0;
			String colmonthThemeName = null;
			String colweekThemeName = null;
			int coldevelopmentDomain = 0;
			int colaggrandizementDomain = 0;
			int colactivityType = 0;
			String coltpYear = null;
			
			if(request.getParameter("ColTPType") != null && !request.getParameter("ColTPType").equals("")){
				coltpType = Integer.parseInt(request.getParameter("ColTPType"));
			}
			if(request.getParameter("ColTPProperty") != null && !request.getParameter("ColTPProperty").equals("")){
				coltpProperty = Integer.parseInt(request.getParameter("ColTPProperty"));
			}
			if(request.getParameter("ColAppropriateAge") != null && !request.getParameter("ColAppropriateAge").equals("")){
				colappropriateAge = Integer.parseInt(request.getParameter("ColAppropriateAge"));
			}
			if(request.getParameter("ColMonthThemeName") != null && !request.getParameter("ColMonthThemeName").equals("")){
				colmonthThemeName = request.getParameter("ColMonthThemeName");
			}
			if(request.getParameter("ColWeekThemeName") != null && !request.getParameter("ColWeekThemeName").equals("")){
				colweekThemeName = request.getParameter("ColWeekThemeName");
				
			}
			if(request.getParameter("ColDevelopmentDomain") != null && !request.getParameter("ColDevelopmentDomain").equals("")){
				coldevelopmentDomain = Integer.parseInt(request.getParameter("ColDevelopmentDomain"));
			}
			if(request.getParameter("ColAggrandizementDomain") != null && !request.getParameter("ColAggrandizementDomain").equals("")){
				colaggrandizementDomain = Integer.parseInt(request.getParameter("ColAggrandizementDomain"));
			}
			if(request.getParameter("ColActivityType") != null && !request.getParameter("ColActivityType").equals("")){
				colactivityType = Integer.parseInt(request.getParameter("ColActivityType"));
			}
			if(request.getParameter("ColTPYear") != null && !request.getParameter("ColTPYear").equals("")){
				coltpYear = request.getParameter("ColTPYear");
				
			}
//			String userName = request.getSession().getAttribute("UserName").toString();
			
			try{
				request.setAttribute("pageNoColl", nPageNo);
				ArrayList alColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					iiColl++;
					TeachingPlanBaseInfo t = itColl.next();
					if(iiColl <= PageSizeColl * (nPageNo - 1))
						continue;
					
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
					tpbiColl.setEditingTimes(t.getEditingTimes());
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					
					if(iiColl > PageSizeColl * nPageNo - 1){
						break;
					}
					
				}
				
				request.setAttribute("collectionTPList", alColl);
//				request.setAttribute("TPList", tpbiDAO.getTPByUserName(
//						request.getSession().getAttribute("UserName").toString()));
				
				request.setAttribute("pageNo", 1);
				int PageSize = Utility.PageSize;
				
				int tpType = 0;
				int tpProperty = 0;
				int appropriateAge = 0;
				String monthThemeName = null;
				String weekThemeName = null;
				int developmentDomain = 0;
				int aggrandizementDomain = 0;
				int activityType = 0;
				String tpYear = null;
				
				if(request.getParameter("TPType") != null && !request.getParameter("TPType").equals("")){
					tpType = Integer.parseInt(request.getParameter("TPType"));
				}
				if(request.getParameter("TPProperty") != null && !request.getParameter("TPProperty").equals("")){
					tpProperty = Integer.parseInt(request.getParameter("TPProperty"));
				}
				if(request.getParameter("AppropriateAge") != null && !request.getParameter("AppropriateAge").equals("")){
					appropriateAge = Integer.parseInt(request.getParameter("AppropriateAge"));
				}
				if(request.getParameter("MonthThemeName") != null && !request.getParameter("MonthThemeName").equals("")){
					monthThemeName = request.getParameter("MonthThemeName");
				}
				if(request.getParameter("WeekThemeName") != null && !request.getParameter("WeekThemeName").equals("")){
					weekThemeName = request.getParameter("WeekThemeName");
					
				}
				if(request.getParameter("DevelopmentDomain") != null && !request.getParameter("DevelopmentDomain").equals("")){
					developmentDomain = Integer.parseInt(request.getParameter("DevelopmentDomain"));
				}
				if(request.getParameter("AggrandizementDomain") != null && !request.getParameter("AggrandizementDomain").equals("")){
					aggrandizementDomain = Integer.parseInt(request.getParameter("AggrandizementDomain"));
				}
				if(request.getParameter("ActivityType") != null && !request.getParameter("ActivityType").equals("")){
					activityType = Integer.parseInt(request.getParameter("ActivityType"));
				}
				if(request.getParameter("TPYear") != null && !request.getParameter("TPYear").equals("")){
					tpYear = request.getParameter("TPYear");
					
				}
				
				
				ArrayList al = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear);
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (al.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					TeachingPlanBaseInfo t = it.next();
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
					tpbi.setEditingTimes(t.getEditingTimes());
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);
					ii++;
		
					if(ii > (PageSize-1) ) {
						break;
					}
				}
				
			
				request.setAttribute("TPList", al);
				
				
			} catch (SQLException st){
				st.printStackTrace();
			}
			request.setAttribute(WebConstants.DIVSHOW, WebConstants.DIV_COLL);
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
		} else if (strFunc.equals("SearchCondition")) {
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			TeachingPlanBaseInfo tpbi = null;
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int tpType = 0;
			int tpProperty = 0;
			int appropriateAge = 0;
			String monthThemeName = null;
			String weekThemeName = null;
			int developmentDomain = 0;
			int aggrandizementDomain = 0;
			int activityType = 0;
			String tpYear = null;
			
			if(request.getParameter("TPType") != null && !request.getParameter("TPType").equals("")){
				tpType = Integer.parseInt(request.getParameter("TPType"));
			}
			if(request.getParameter("TPProperty") != null && !request.getParameter("TPProperty").equals("")){
				tpProperty = Integer.parseInt(request.getParameter("TPProperty"));
			}
			if(request.getParameter("AppropriateAge") != null && !request.getParameter("AppropriateAge").equals("")){
				appropriateAge = Integer.parseInt(request.getParameter("AppropriateAge"));
			}
			if(request.getParameter("MonthThemeName") != null && !request.getParameter("MonthThemeName").equals("")){
				monthThemeName = request.getParameter("MonthThemeName");
			}
			if(request.getParameter("WeekThemeName") != null && !request.getParameter("WeekThemeName").equals("")){
				weekThemeName = request.getParameter("WeekThemeName");
				
			}
			if(request.getParameter("DevelopmentDomain") != null && !request.getParameter("DevelopmentDomain").equals("")){
				developmentDomain = Integer.parseInt(request.getParameter("DevelopmentDomain"));
			}
			if(request.getParameter("AggrandizementDomain") != null && !request.getParameter("AggrandizementDomain").equals("")){
				aggrandizementDomain = Integer.parseInt(request.getParameter("AggrandizementDomain"));
			}
			if(request.getParameter("ActivityType") != null && !request.getParameter("ActivityType").equals("")){
				activityType = Integer.parseInt(request.getParameter("ActivityType"));
			}
			if(request.getParameter("TPYear") != null && !request.getParameter("TPYear").equals("")){
				tpYear = request.getParameter("TPYear");
				
			}
			
			
			try {
				request.setAttribute("TPList", tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear));
				ArrayList coll = new ArrayList();
				coll = tpbiDAO.getCollectTPByUserName(teacherID);
				if(coll != null){
				request.setAttribute("collectionTPList", tpbiDAO.getCollectTPByUserName(teacherID));
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
		
			try {
				request.setAttribute("pageNo", 1);
				int PageSize = Utility.PageSize;
				ArrayList al = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear);
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (al.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getMySearchCondition(tpType, tpProperty, appropriateAge, monthThemeName, weekThemeName, developmentDomain, aggrandizementDomain, activityType, teacherID, tpYear).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					TeachingPlanBaseInfo t = it.next();
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
//					tpbi.setEditingTimes(t.getEditingTimes());
					int times = tpbiDAO.getTemplateUsedTimes(t.getTpID());
					tpbi.setEditingTimes(times);
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);
					ii++;
		
					if(ii > (PageSize-1) ) {
						break;
					}
				}
				
				
				TeachingPlanBaseInfo tpbiColl = null;
				request.setAttribute("TPList", al);
				//Coll paging
				request.setAttribute("pageNoColl", 1);
				int PageSizeColl = Utility.PageSize;
				ArrayList alColl = tpbiDAO.getCollectTPByUserName(teacherID);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getCollectTPByUserName(teacherID).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					TeachingPlanBaseInfo t = itColl.next();
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
//					tpbiColl.setEditingTimes(t.getEditingTimes());
					int times1 = tpbiDAO.getTemplateUsedTimes(t.getTpID());
					tpbiColl.setEditingTimes(times1);
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					iiColl++;
		
					if(iiColl > (PageSizeColl-1) ) {
						break;
					}
				}
				
				request.setAttribute("collectionTPList", alColl);
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
			
		} else if (strFunc.equals("ColSearchCondition")) {
			TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
			
			TeachingPlanBaseInfo tpbi = null;
			com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
			
			Integer teacherID = teacher.getTeacherId();
			
			int coltpType = 0;
			int coltpProperty = 0;
			int colappropriateAge = 0;
			String colmonthThemeName = null;
			String colweekThemeName = null;
			int coldevelopmentDomain = 0;
			int colaggrandizementDomain = 0;
			int colactivityType = 0;
			String coltpYear = null;
			
			if(request.getParameter("ColTPType") != null && !request.getParameter("ColTPType").equals("")){
				coltpType = Integer.parseInt(request.getParameter("ColTPType"));
			}
			if(request.getParameter("ColTPProperty") != null && !request.getParameter("ColTPProperty").equals("")){
				coltpProperty = Integer.parseInt(request.getParameter("ColTPProperty"));
			}
			if(request.getParameter("ColAppropriateAge") != null && !request.getParameter("ColAppropriateAge").equals("")){
				colappropriateAge = Integer.parseInt(request.getParameter("ColAppropriateAge"));
			}
			if(request.getParameter("ColMonthThemeName") != null && !request.getParameter("ColMonthThemeName").equals("")){
				colmonthThemeName = request.getParameter("ColMonthThemeName");
			}
			if(request.getParameter("ColWeekThemeName") != null && !request.getParameter("ColWeekThemeName").equals("")){
				colweekThemeName = request.getParameter("ColWeekThemeName");
				
			}
			if(request.getParameter("ColDevelopmentDomain") != null && !request.getParameter("ColDevelopmentDomain").equals("")){
				coldevelopmentDomain = Integer.parseInt(request.getParameter("ColDevelopmentDomain"));
			}
			if(request.getParameter("ColAggrandizementDomain") != null && !request.getParameter("ColAggrandizementDomain").equals("")){
				colaggrandizementDomain = Integer.parseInt(request.getParameter("ColAggrandizementDomain"));
			}
			if(request.getParameter("ColActivityType") != null && !request.getParameter("ColActivityType").equals("")){
				colactivityType = Integer.parseInt(request.getParameter("ColActivityType"));
			}
			if(request.getParameter("ColTPYear") != null && !request.getParameter("ColTPYear").equals("")){
				coltpYear = request.getParameter("ColTPYear");
				
			}
			
			try {
				
				request.setAttribute("TPList", tpbiDAO.getTPByUserName(teacherID));
				ArrayList coll = new ArrayList();
				coll = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear);
				if(coll != null){
				request.setAttribute("collectionTPList", coll);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}

		
			try {
				request.setAttribute("pageNo", 1);
				int PageSize = Utility.PageSize;
				ArrayList al = tpbiDAO.getTPByUserName(teacherID);
				int totalPage = 0;
				if (al.size() % PageSize == 0) {
					totalPage = al.size()/PageSize;
					request.setAttribute("totalPage",totalPage);
				} else {
					totalPage = (al.size()/PageSize) + 1;
					request.setAttribute("totalPage",totalPage);
				}
				
				al = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getTPByUserName(teacherID).listIterator();
				int ii = 0;
				while (it.hasNext()) {
					TeachingPlanBaseInfo t = it.next();
					tpbi = new TeachingPlanBaseInfo();
					tpbi.setActivityName(t.getActivityName());
//					tpbi.setEditingTimes(t.getEditingTimes());
					int times = tpbiDAO.getTemplateUsedTimes(t.getTpID());
					tpbi.setEditingTimes(times);
					tpbi.setTeacherName(t.getTeacherName());
					tpbi.setTpType(t.getTpType());
					tpbi.setTpID(t.getTpID());
					al.add(tpbi);
					ii++;
		
					if(ii > (PageSize-1) ) {
						break;
					}
				}
				
				
				TeachingPlanBaseInfo tpbiColl = null;
				request.setAttribute("TPList", al);
				//Coll paging
				request.setAttribute("pageNoColl", 1);
				int PageSizeColl = Utility.PageSize;
				ArrayList alColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear);
				int totalPageColl = 0;
				if (alColl.size() % PageSizeColl == 0) {
					totalPageColl = alColl.size()/PageSizeColl;
					request.setAttribute("totalPageColl",totalPageColl);
				} else {
					totalPageColl = (alColl.size()/PageSizeColl) + 1;
					request.setAttribute("totalPageColl",totalPageColl);
				}
				
				alColl = new ArrayList<TeachingPlanBaseInfo>();
				ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getColSearchCondition(coltpType, coltpProperty, colappropriateAge, colmonthThemeName, colweekThemeName, coldevelopmentDomain, colaggrandizementDomain, colactivityType, teacherID, coltpYear).listIterator();
				int iiColl = 0;
				while (itColl.hasNext()) {
					TeachingPlanBaseInfo t = itColl.next();
					tpbiColl = new TeachingPlanBaseInfo();
					tpbiColl.setActivityName(t.getActivityName());
//					tpbiColl.setEditingTimes(t.getEditingTimes());
					int times1 = tpbiDAO.getTemplateUsedTimes(t.getTpID());
					tpbiColl.setEditingTimes(times1);
					tpbiColl.setTeacherName(t.getTeacherName());
					tpbiColl.setTpType(t.getTpType());
					tpbiColl.setTpID(t.getTpID());
					alColl.add(tpbiColl);
					iiColl++;
		
					if(iiColl > (PageSizeColl-1) ) {
						break;
					}
				}
				
				request.setAttribute("collectionTPList", alColl);
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.getRequestDispatcher("../" + Utility.JSP_MyTeachingPlan).forward(request, response);
			
		}
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}
	public void myTeachingPlan(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException{
		TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
		com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
		
		Integer teacherID = teacher.getTeacherId();
		try {
			
			
			request.setAttribute("TPList", tpbiDAO.getTPByUserName(teacherID));
			ArrayList coll = new ArrayList();
			coll = tpbiDAO.getCollectTPByUserName(teacherID);
			if(coll != null){
			request.setAttribute("collectionTPList", tpbiDAO.getCollectTPByUserName(teacherID));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		TeachingPlanBaseInfo tpbi = null;
	
		try {
			request.setAttribute("pageNo", 1);
			int PageSize = Utility.PageSize;
			ArrayList al = tpbiDAO.getTPByUserName(teacherID);
			int totalPage = 0;
			if (al.size() % PageSize == 0) {
				totalPage = al.size()/PageSize;
				request.setAttribute("totalPage",totalPage);
			} else {
				totalPage = (al.size()/PageSize) + 1;
				request.setAttribute("totalPage",totalPage);
			}
			
			al = new ArrayList<TeachingPlanBaseInfo>();
			ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getTPByUserName(teacherID).listIterator();
			int ii = 0;
			while (it.hasNext()) {
				TeachingPlanBaseInfo t = it.next();
				tpbi = new TeachingPlanBaseInfo();
				tpbi.setActivityName(t.getActivityName());
//				tpbi.setEditingTimes(t.getEditingTimes());
				int times = tpbiDAO.getTemplateUsedTimes(t.getTpID());
				tpbi.setEditingTimes(times);
				tpbi.setTeacherName(t.getTeacherName());
				tpbi.setTpType(t.getTpType());
				tpbi.setTpID(t.getTpID());
				al.add(tpbi);
				ii++;
	
				if(ii > (PageSize-1) ) {
					break;
				}
			}
			
			
			TeachingPlanBaseInfo tpbiColl = null;
			request.setAttribute("TPList", al);
			//Coll paging
			request.setAttribute("pageNoColl", 1);
			int PageSizeColl = Utility.PageSize;
			ArrayList alColl = tpbiDAO.getCollectTPByUserName(teacherID);
			int totalPageColl = 0;
			if (alColl.size() % PageSizeColl == 0) {
				totalPageColl = alColl.size()/PageSizeColl;
				request.setAttribute("totalPageColl",totalPageColl);
			} else {
				totalPageColl = (alColl.size()/PageSizeColl) + 1;
				request.setAttribute("totalPageColl",totalPageColl);
			}
			
			alColl = new ArrayList<TeachingPlanBaseInfo>();
			ListIterator<TeachingPlanBaseInfo> itColl = tpbiDAO.getCollectTPByUserName(teacherID).listIterator();
			int iiColl = 0;
			while (itColl.hasNext()) {
				TeachingPlanBaseInfo t = itColl.next();
				tpbiColl = new TeachingPlanBaseInfo();
				tpbiColl.setActivityName(t.getActivityName());
//				tpbiColl.setEditingTimes(t.getEditingTimes());
				int times1 = tpbiDAO.getTemplateUsedTimes(t.getTpID());
				tpbiColl.setEditingTimes(times1);
				tpbiColl.setTeacherName(t.getTeacherName());
				tpbiColl.setTpType(t.getTpType());
				tpbiColl.setTpID(t.getTpID());
				alColl.add(tpbiColl);
				iiColl++;
	
				if(iiColl > (PageSizeColl-1) ) {
					break;
				}
			}
			
			request.setAttribute("collectionTPList", alColl);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void collectionTeachingPlan(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException, SQLException{
		String strTPID = request.getParameter("colTPID");
		TeachingPlanBaseInfoDAO tpbiDAO = new TeachingPlanBaseInfoDAO();
		TeachingPlanBaseInfo tpbi = tpbiDAO.getTPByTPID(strTPID);
		int PageSize = Utility.PageSize;
		String tmp = request.getParameter("collectionPageNo");
		int nPageNo = Integer.parseInt(tmp); 
		com.zmht.specedu.vo.Teacher teacher = this.getCurrentUser(request); 
		
		Integer teacherID = teacher.getTeacherId();
		
		ArrayList collTP = new ArrayList();
		collTP = tpbiDAO.getCollectTPByUserName(teacherID);	
		

//		ArrayList alTP = tpbiDAO.getTPByUserName(request.getSession().getAttribute("UserName").toString());
		int totalPage = 0;
		if (collTP.size() % PageSize == 0) {
			totalPage = collTP.size()/PageSize;
			request.setAttribute("collectionTotalPage",totalPage);
		} else {
			totalPage = (collTP.size()/PageSize) + 1;
			request.setAttribute("collectionTotalPage",totalPage);
		}
		
		
		request.setAttribute("collectionPageNo", 1);
		
		ArrayList<TeachingPlanBaseInfo> al = new ArrayList<TeachingPlanBaseInfo>();
		ListIterator<TeachingPlanBaseInfo> it = tpbiDAO.getCollectTPByUserName(teacherID).listIterator();
		int ii = 0;
		while (it.hasNext()) {
			TeachingPlanBaseInfo t = it.next();
			
			
			tpbi = new TeachingPlanBaseInfo();
			tpbi.setActivityName(t.getActivityName());
			tpbi.setTeacherName(t.getTeacherName());
			tpbi.setEditingTimes(t.getEditingTimes());
			tpbi.setTpType(t.getTpType());
			tpbi.setTpID(t.getTpID());
			al.add(tpbi);
			
			ii++;
			if(ii > (PageSize-1) ) {
				break;
			}
			
		}
		
		
		request.setAttribute("collectionTPList", al);
		
		
	}

}
